package com.detech.sbom.base.domain;

import io.swagger.annotations.ApiModelProperty;
import org.springframework.http.HttpStatus;

public class Message<T> {

    @ApiModelProperty(value = "状态码")
    public int code;
    @ApiModelProperty(value = "描述信息")
    public String msg;
    @ApiModelProperty(value = "业务数据")
    public T data;

    public Message(){

    }

    public Message(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Message(int code, String msg, T data) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public static <T> Message<T> custom(int code, String msg, T data) {
        return new Message(code, msg, data);
    }

    public static <T> Message<T> custom(int code, String msg) {
        return new Message(code, msg);
    }

    public static HttpStatus num2HttpStatus(int code) {
        HttpStatus status = HttpStatus.NOT_FOUND;
        for (HttpStatus httpStatus : HttpStatus.values()) {
            boolean b = code == httpStatus.value();
            if (b) {
                return httpStatus;
            }
        }
        return status;
    }
}
